﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;

namespace Cliente {
    class Program : ServiceReference2.IMyServiceCallback   {
        ServiceReference2.MyServiceClient client2 ;
        ServiceReference2.IMyService client3;
         public Program() {
            client2 = new ServiceReference2.MyServiceClient(new InstanceContext(this));
           
         }
        
        static void Main(string[] args) {

            try {
                Program p = new Program();
                Console.WriteLine("voy!!");
                Console.ReadLine();
                //  Console.WriteLine( client1.metodo());
                Console.WriteLine("Normal:");
                Console.WriteLine(p.client2.metodo());

                Console.WriteLine("oneWay:");
                p.client2.OneWay();
                Console.WriteLine("listo!");

                Console.WriteLine("DataContract:");

                Console.WriteLine(p.client2.datacontractResponse().nombre);


                //crarProxy();

                //Console.WriteLine(client3.metodo());
                Console.ReadLine();
            } catch (FaultException<ServiceReference2.Error> f) {
                Console.WriteLine(f.Detail.erroGeneral);
                Console.ReadLine();

            } catch (Exception e) {
                Console.WriteLine(e.Message);
                Console.ReadLine();
            }
            }

        private  void crarProxy() {
            WSHttpBinding binding = new WSHttpBinding();
            WSHttpSecurity sec = new WSHttpSecurity();
            sec.Mode = SecurityMode.None;
            binding.Security = sec;
            client3 = ChannelFactory<ServiceReference2.IMyService>.CreateChannel(binding, new EndpointAddress("http://localhost:8002/midominio/host"));

        }


        public void listo(string msj) {
            Console.WriteLine(msj);
        }
    }
}
